package com.cloud.service.impl;

import org.apache.kafka.common.requests.IsolationLevel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.transaction.support.TransactionTemplate;

import javax.sql.DataSource;

// 使用Spring的TransactionSynchronizationManager传播事务
//@Configuration
//@EnableTransactionManagement
//public class TransactionConfig {
//
//    @Bean
//    public TransactionTemplate transactionTemplate(DataSource dataSource) {
//        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
//        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
//        def.setIsolationLevel(IsolationLevel.READ_COMMITTED);
//        return new TransactionTemplate(dataSource, def);
//    }
//}